package com.shroo8.footballblog.controllers.test;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.shroo8.footballblog.bo.test.GetCommentsBo;
import com.shroo8.footballblog.dto.api.CommentDto;

@Controller
public class ViewCommentsController {

	private static final Logger logger = LoggerFactory.getLogger(ViewCommentsController.class);

	@Resource(name="getCommentsBo", type=com.shroo8.footballblog.bo.test.GetCommentsBoImpl.class)
	GetCommentsBo getCommentsBo;
	
	@RequestMapping(value = "/viewcomments", method = RequestMethod.GET)
	public ModelAndView viewComments(Locale locale, Model model, @RequestParam("articleId") String articleId) {
		logger.info("Testing: Welcome to the test viewCommentsController! The client locale is {}.", locale);
		
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
		String formattedDate = dateFormat.format(date);
		model.addAttribute("serverTime", formattedDate );
		
		logger.info("articleId is: " + articleId);
		
		ArrayList<CommentDto> commentsDto = getCommentsBo.getComments(articleId);
		
		return new ModelAndView("viewComments", "comments", commentsDto);
	}

}
